﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using XmlVisualizer.Controls;
using XmlVisualizer.Models;

namespace XmlVisualizer.Dialogs {
	/// <summary>
	/// Interaction logic for DialogChangeAppearance.xaml
	/// </summary>
	public partial class DialogChangeAppearance : Window {
		#region Fields
		bool posAdjusted = false;
		string appearance = String.Empty;
		#endregion

		public DialogChangeAppearance() {
			InitializeComponent();
		}

		#region Event handlers
		/// <summary>
		/// Invoked when window gets activated.
		/// </summary>
		/// <param name="e">The event data.</param>
		protected override void OnActivated(EventArgs e) {
			base.OnActivated(e);
			if (!posAdjusted) {
				this.Left -= this.ActualWidth;
				this.Top -= this.ActualHeight;
				posAdjusted = true;
			}
		}

		private void Button_Click(object sender, RoutedEventArgs e) {
			if (border_Appearances.Child is ComboBox) {
				ComboBox cb = border_Appearances.Child as ComboBox;
				object selectedItem = cb.SelectedItem;
				if (selectedItem is ComboBoxItem) {
					ComboBoxItem selectedComboBoxItem = selectedItem as ComboBoxItem;
					appearance = selectedComboBoxItem.Tag as String;
				}
			}
			Close();
		}
		#endregion

		/// <summary>
		/// Displays and shows the window until user closes it.
		/// </summary>
		/// <returns></returns>
		public string ShowModal() {
			ShowDialog(); // this "blocks" until window is closed
			return appearance;
		}
	}
}
